package com.szyibei.system.authorization.controller;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.szyibei.system.common.utils.LoggerUtil;
import com.szyibei.system.common.vo.RequestBaseVO;

import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
public class TestController {
    @RequestMapping("/test")
    public Map<String,String> hello(@RequestBody(required = false) RequestBaseVO vo) {
      LoggerUtil.info(log, "auth test{}", JSON.toJSONString(vo));
      System.out.println(JSON.toJSONString(vo));
      Map<String,String> mp = new HashMap<>();
      mp.put("1", "hello");
      mp.put("2", "hi");
      return mp;
              
    }
    
    @PostMapping("/testa")
    public Map<String,String> helloa(HttpServletRequest request) {
      Map<String, String> requestParams = getRequestParams(request);
      System.out.println(JSON.toJSONString(requestParams));
      Map<String,String> mp = new HashMap<>();
      mp.put("1", "hello");
      mp.put("2", "hi");
      return mp;
              
    }
    
    
    public static Map<String, String> getRequestParams(HttpServletRequest request) {
        Map<String, String> map = new HashMap<String, String>();
        @SuppressWarnings("unchecked")
        Enumeration<String> er = request.getParameterNames();
        while (er.hasMoreElements()) {
            String name = (String) er.nextElement();
            String value = request.getParameter(name);
            map.put(name, value);
        }
        return map;
    }
}
